import {Asset} from '@/store/modules/types/Asset'
import {AssetStock} from '@/store/modules/types/AssetStock'
import {find} from 'lodash'
import {KeyValueLabel, SampleKeyValue} from '@/store/modules/types/Order'

export interface Selectable {
  isSelected?: boolean;
}

export interface WithId {
  id?: number | string | null;
}

export interface Rentalable extends WithId {
  type: string
  name: string
}

export interface OrderBundle extends Selectable, WithId {
  name: string;
  items: Item[]; // Items 指向的是每个budnle filter
  amount?: number;
  rental_out_at?: Date;
  return_at?: Date;
  selected?: number;
  isSelected: boolean;
}

export interface Item extends Selectable {
  criteria: Criteria;
  data: AssetStock[] | Asset[];
  selected?: null | number;
  isSelected?: boolean;
}

export interface Criteria {
  id: number;
  bundle_id: number;
  asset_type: string;
  field_name: string;
  field_value: string;
  operator: string;
  quantity: number;
  deleted_at: any;
  created_at: string;
  updated_at: string;
}

export const CriteriaOperationTypes: SampleKeyValue[] = [
  { key: '=', lbl: '等于' },
  { key: '!=', lbl: '不等于' },
  { key: 'like', lbl: '包含' },
  { key: 'not like', lbl: '不包含' },
  { key: '>', lbl: '大于' },
  { key: '<', lbl: '小于' }
]

export const AssetTypes: SampleKeyValue[] = [
  { key: 'App\\Models\\Asset', lbl: '一般资产' },
  { key: 'App\\Models\\AssetStock', lbl: '批量资产' },
]

export const CriteriaFilterTypes: SampleKeyValue[] = [
  { key: 'name', lbl: '名称' },
  { key: 'category', lbl: '分类' },
]

export function getLabelByKey(data: SampleKeyValue[], key: string): string {
  let item = find(data, { key })
  return item ? <string>item.lbl : 'N/A'
}